package org.wit.ecommerce.dao;

import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.wit.ecommerce.domain.Discount;
/**
 * @spring.bean id="discountDao"
 * @spring.property name="sessionFactory" ref="sessionFactoryObj"
 * @author Justin
 *
 */
public class DiscountDao extends SimpleHibernateDao<Discount, Long> {

	@SuppressWarnings("unchecked")
	public List<Discount> findByPage(int start, int limit, Map<String, ?> keywords) {
		String hql = "from org.wit.ecommerce.domain.Discount";
		Query query = createQuery(hql, keywords);
		query.setFirstResult(start);
		query.setMaxResults(limit);
		return query.list();
	}

	public int getTotalCount(Map<String, ?> keywords) {
		String hql = "select count(*) from org.wit.ecommerce.domain.Discount";
		return ((Number) createQuery(hql, keywords).uniqueResult()).intValue();
	}

}
